"""该方法返回一个可用的代理ip   将该方法配置到urls文件里面"""
from .models import ProxyIp
import random
from django.shortcuts import HttpResponse

def get_proxyip(request):
    proxyips = ProxyIp.objects.filter(valid=True)
    proxyip = random.choice(proxyips)
    if proxyips.count() < 1:
        return HttpResponse("Without Proxyip")
    else:
        return HttpResponse("{}:{}".format(proxyip.ip,proxyip.port))
